<template>
  <div id="setId">
    <u-navbar :is-back="false" title="设置密码" :is-fixed="true" title-color="#000" :border-bottom="false"></u-navbar>
    <div class="icon-style col-fff text-cent font-46">
      <img src="https://app.zbzedu.com/static/WaChat/img/set_pw.png" />
    </div>
    <div class="font-28 col-333 text-cent">请设置登录密码</div>
    <div class="font-28 col-333 text-cent pd_b_45">后期也可通过手机号+密码方式登录</div>
    <div class="pd_l_30 pd_r_30 pd_t_60">
      <div class="font-26 yh_bd_bottom pd_t_30 pd_b_20">
        <input type="password" class="col-333" v-model="password" id="password" value="" placeholder="请输入密码" />
      </div>
      <div class="font-26 yh_bd_bottom pd_t_30 pd_b_20">
        <input type="password" class="col-333" v-model="repassword" id="password1" value="" placeholder="请再次输入密码" />
      </div>
    </div>
    <div class="user-btn text-cent col-fff font-30 bg-1f476d" @click="login">确认</div>
    <div class="skip-btn text-cent col-666 font-30" @click="firstDataInput">跳过</div>
		</div>
</template>

<script>
	import {TOAST} from "../../util/util";
	import {request} from "../../util/api";

	export default {
		data() {
			return {
        password: '',
        repassword: ''
			}
		},

		methods: {
		  checkPassword(password) {
				if (!password || password.length < 6) {
					TOAST('密码至少6位');
					return false;
				}
				var passwordReg = /[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/;
				if (passwordReg.test(password)) {
					return true;
				} else {
					TOAST('密码必须包含数字、字母')
					return false;
				}
			},
      openWindow: function(path, type) {
        this.$u.route({
          url: path,
          type: type
        })
      },
			login: function() {
        var that_ = this;
        if (!this.checkPassword(this.password)) return false;
        if (this.password != this.repassword) {
          TOAST('两次密码不相同');
          return false;
        }
        request({
          url: '/app/base/setPassword',
          method: 'post',
          data: {
            "password": this.password,
            "repassword": this.repassword,
          }
        }).then(ret => {
          TOAST('设置密码成功');
          that_.openWindow('/package/login/infomation_entry', 'reLaunch')
        })
      },
      firstDataInput: function() {
        request({
          url: '/app/base/firstDataInput'
        }).then(ret => {
          if (ret.data) {
            this.openWindow('/package/login/infomation_entry', 'reLaunch')
          } else {
            api.rebootApp();
          }
        })
      }
		}
	}
</script>

<style lang="scss" scoped>
	.user-btn {
				width: 90%;
				height: 88upx;
				border-radius: 44upx;
				line-height: 88upx;
				margin: 150upx auto 0;
			}

			.icon-style{
				width: 160upx;
				height: 160upx;
				margin: 70upx auto 0;
			}

			.icon-style img{
				width: 100%;
				height: 100%;
			}

			.user-btn {
				width: 90%;
				height: 88upx;
				border-radius: 44upx;
				line-height: 88upx;
				margin: 260upx auto 50upx;
			}

			.skip-btn {
				width: 90%;
				height: 88upx;
				border-radius:44upx;
				line-height: 88upx;
				border: 1upx solid #CCCCCC;
				margin: 0 auto;
			}
	.bg-1f476d {
		background: #1f476d;
	}
</style>
